package datastructure.segmenttree;

/**
 * @author XY
 * @version 1.0.0
 * @ClassName NumArray.java
 * @createTime 2021年12月20日 19:27:00
 */
public class NumArray {
    private SegmentTree<Integer> segmentTree;

    public NumArray(int[] nums) {
        Integer[] data = new Integer[nums.length];
        for (int i = 0; i < nums.length; i++) {
            data[i] = nums[i];
        }
        segmentTree = new SegmentTree<>(data, Integer::sum);

    }

    public int sumRange(int left, int right) {
        return segmentTree.query(left,right);
    }
}
